<!DOCTYPE html>
<html>
    <head>
        <title>AGM客服对话用户列表</title>
        <link rel="stylesheet" href="/static/weui.min.css">
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style>
            .page, body{background-color: #fbf9fe}
            .page_title{color:#225fba}
            .hd{text-align:center}
            .weui_label{width:4em;}
            .bd{padding-bottom:30px;}
            .weui_cell_hd img{height: 40px;}
            .weui_cell_bd {
                white-space: nowrap;
                overflow: auto;
            }
            .limt_t{
                position: absolute;
                left: 65px;
                bottom: 0px;
                font-size: 0.85em;                
            }
            .nav_right{position: absolute;right: 5px;width: 35px;top: 5px;}
            .weui_actionsheet_menu a .weui_actionsheet_cell{color:initial;border-top: 1px solid #d9d9d9;} 
        </style>
    </head>
    <body>
        <div id='wx_logo' style="display:none;"><img src="/static/images/wx_logo.jpg"/></div>
        <div class="hd">
            <h2 class="page_title">AGM客服对话用户列表</h2> 
        </div>
        <div class="bd">
            <div class="weui_cells weui_cells_access">
                {% for user in users %}
                <a class="weui_cell" href="kfchat?uid={{ user.id }}">
                    <div class="weui_cell_hd"><img src="{{ user.get('headimgurl') or '/static/images/getheadimg.png' }}"></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <p>{{ user.get('nickname_emoji') or user.get('nickname') }}</p>
                    </div>
                    <div class="weui_cell_ft">
                        <div class="limt_t">{% set timetemp=convertTime(info[user.get('openid')][0], now) %}{% if timetemp[0] %}{{ timetemp[0] }}小时{% endif %}{% if timetemp[1] %}{{ timetemp[1] }}分钟{% endif %}{% if timetemp[2] %}{{ timetemp[2] }}秒{% endif %}后 失效</div>
                        <button class="weui_btn weui_btn_mini weui_btn_primary refreshbtn" data_id="{{ user.get('openid') }}">更新</button>
                    </div>
                </a>
                {% endfor %} 
            </div>
        </div>        
    </body>
    <script>
        $('.refreshbtn:not(.weui_btn_disabled)').click(function(e){
            e.preventDefault();
            var self = $(this)
            var cell = self.parents('.weui_cell')
            self.addClass('weui_btn_disabled')
            var openid = $(this).attr('data_id')
            $.post('?action=refrehuser&openid='+openid, function(data){
                console.info(data)
                if(data.headimgurl){
                    cell.find('.weui_cell_hd img').attr('src', data.headimgurl)                    
                // }else{
                    // cell.find('.weui_cell_hd img').attr('src', '/static/images/getheadimg.png') 
                }
                if(data.nickname){
                    cell.find('.weui_cell_primary p').text(data.nickname)
                }
                self.remove()
            }, 'json')
        })
        countTime = function(e){
            var text = e.text()
            var hour = text.match(/(\d+)小时/)?parseInt(text.match(/(\d+)小时/)[1]):0
            var min = text.match(/(\d+)分钟/)?parseInt(text.match(/(\d+)分钟/)[1]):0
            var sec = text.match(/(\d+)秒/)?parseInt(text.match(/(\d+)秒/)[1]):0
            if(sec==0){
                if(min==0){
                    if(hour!=0){
                        hour -= 1
                        min = 59
                    }
                }else{
                    min -=1
                    sec = 59
                }
            }else{
                sec -= 1
            }
            if(!sec&!min&!hour){
                e.parents('.weui_cell').remove()
            }else{
                hour = hour?hour+"小时":""
                min = min?min+"分钟":""
                sec = sec?sec+"秒":""
                e.text(hour+min+sec+"后 失效")
            }
        }
        countAll = function(){
            var limits = $('.limt_t')
            if(!limits.length&&countT){
                clearInterval(countT)
            }else{
                limits.each(function(){
                    var self = $(this)
                    countTime(self)
                })
            }           
        }
        var countT = setInterval(countAll, 1000)        
    </script>
<html>